﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
namespace AnyOffice.general.attend.personal
{
    public partial class leave_new : ModulePage
    {


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.txtLeaveDate1.Value = DateTime.Now.ToString();
                this.txtLeaveDate2.Value = DateTime.Now.ToString();
                AttendParaDao dao = new AttendParaDao();
                dao.GetPara();
                DataTable table = dao.SelectAttendManager(base.Conn);
                if (table.Rows.Count > 0)
                {
                    this.sltLeaderId.DataSource = table;
                    this.sltLeaderId.DataBind();
                }
                this.ckbMobile.Visible = SmsDao.IsMobile(SmsDao.SmsType.Attend);
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                if (Convert.ToDateTime(this.txtLeaveDate1.Value) >= Convert.ToDateTime(this.txtLeaveDate2.Value))
                {
                    this.litMessage.Text = base.ShowPrompt("请假结束时间应晚于请假开始时间");
                }
                else
                {
                    AttendLeaveDao dao2 = new AttendLeaveDao();
                    AttendLeaveData data = new AttendLeaveData();
                    data.UserId = base.User.Identity.Name;
                    data.LeaderId = this.sltLeaderId.Value;
                    if (this.txtLeaveType.Value != string.Empty)
                    {
                        data.LeaveType = this.txtLeaveType.Value;
                    }
                    data.LeaveDate1 = Convert.ToDateTime(this.txtLeaveDate1.Value);
                    data.LeaveDate2 = Convert.ToDateTime(this.txtLeaveDate2.Value);
                    dao2.Insert(base.Conn, data);
                    if (this.sltLeaderId.Value != string.Empty)
                    {
                        SmsData data2 = new SmsData();
                        SmsDao dao3 = new SmsDao();
                        data2.Type = 6;
                        data2.FromId = base.User.Identity.Name;
                        data2.ToId = this.sltLeaderId.Value;
                        data2.Content = new UserCache().UserName + "提交请假申请，请批示！";
                        data2.RemindFlag = true;
                        data2.Url = "/general/attend/manage";
                        data2.SendTime = DateTime.Now;
                        dao3.BizSend(base.Conn, data2, true, this.ckbMobile.Checked);
                    }
                    this.litMessage.Text = base.ShowPrompt("请假申请添加成功！", "leave.aspx");
                }
            }
        } 

    }
}
